<template>
    <div class="">
        <el-dialog title="编辑风险排查" :visible.sync="dialog" width="60%" :before-close="dialogClose">
            <el-form ref="formData" :model="formData" label-width="140px">
				<el-form-item label="所属户档" prop="hamletid">
				    <el-select v-model="formData.homeid" style="width: 100%;" placeholder="请选择所属户档">
				    	<el-option :label="item.header" :value="item.id" v-for="(item, index) in Home"></el-option>
				    </el-select>
				</el-form-item>
				<el-row>
					<el-col :span="8">
						<el-form-item label="排查方式" prop="type">
						    <el-select v-model="formData.type" style="width: 100%;" placeholder="请选择排查方式">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.checkType"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
					   <el-form-item label="排查日期" prop="amount">
						<el-date-picker
						  v-model="formData.date"
						  type="date"
						  format="yyyy年MM月dd日"
						  value-format="yyyy年MM月dd日"
						  placeholder="请输入年份">
						</el-date-picker>
					   </el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="是否为防返贫监测户" prop="phone">
						    <el-select v-model="formData.households" style="width: 100%;" placeholder="请选择是否为防返贫监测户">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.commonTag"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="8">
						<el-form-item label="姓名" prop="name">
							<el-input v-model="formData.name" placeholder="请输入姓名"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="残疾证号码" prop="name">
							<el-input v-model="formData.sn" placeholder="请输入残疾证号码"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="联系电话" prop="name">
							<el-input v-model="formData.phone" placeholder="请输入联系电话"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-form-item label="家庭地址" prop="addr">
				    <el-input v-model="formData.address" placeholder="请输入家庭地址"></el-input>
				</el-form-item>
				<el-row>
					<el-col :span="8">
						<el-form-item label="就业状况" prop="rate">
						    <el-select v-model="formData.worker" style="width: 100%;" placeholder="请选择就业状况">
						    	<el-option label="是" :value="1"></el-option>
								<el-option label="否" :value="2"></el-option>
						    </el-select>

						</el-form-item>
						<el-form-item v-if="formData.worker">
							<el-select v-if="formData.worker==1" v-model="formData.iswork" style="width: 100%;" placeholder="请选择就业状况">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.isWork"></el-option>
							</el-select>
							<el-select v-else v-model="formData.nowork" style="width: 100%;" placeholder="请选择就业状况">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.noWork"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="适龄就学" prop="rate">
						    <el-select v-model="formData.studyer" style="width: 100%;" placeholder="请选择适龄就学">
						    	<el-option label="是" :value="1"></el-option>
								<el-option label="否" :value="2"></el-option>
						    </el-select>

						</el-form-item>
						<el-form-item v-if="formData.studyer">
							<el-select v-if="formData.studyer==1" v-model="formData.isstudy" style="width: 100%;" placeholder="请选择适龄就学">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.isStudy"></el-option>
							</el-select>
							<el-select v-else v-model="formData.nostudy" style="width: 100%;" placeholder="请选择适龄就学">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.noStudy"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="8">
						<el-form-item label="家庭类别" prop="rate">
						    <el-select v-model="formData.house" style="width: 100%;" placeholder="请选择家庭类别">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.houseStatus"></el-option>
						    </el-select>
						</el-form-item>
					</el-col> 
					<el-col :span="8">
						<el-form-item label="城乡居民医疗保险" prop="rate">
						    <el-select v-model="formData.insurance1" style="width: 100%;" placeholder="请选择城乡居民医疗保险">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.commonJoin"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="政府代缴保费情况" prop="rate" v-if="formData.insurance1=='参加'">
						    <el-select v-model="formData.insurance2" style="width: 100%;" placeholder="请选择政府代缴保费情况">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.commonFlag"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="8">
						<el-form-item label="是否纳入低保" prop="rate">
						    <el-select v-model="formData.issub" style="width: 100%;" placeholder="请选择是否纳入低保">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.commonTag"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="城乡居民养老保险" prop="rate">
						    <el-select v-model="formData.insurance3" style="width: 100%;" placeholder="请选择城乡居民养老保险">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.commonJoin"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="政府代缴保费情况" prop="rate" v-if="formData.insurance3=='参加'">
						    <el-select v-model="formData.insurance4" style="width: 100%;" placeholder="请选择政府代缴保费情况">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.commonFlag"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="8">
						<el-form-item label="是否纳入特困供养" prop="rate">
						    <el-select v-model="formData.ispoverty" style="width: 100%;" placeholder="请选择是否纳入特困供养">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.commonTag"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="是否享受生活补贴" prop="rate">
						    <el-select v-model="formData.isliving" style="width: 100%;" placeholder="请选择是否享受生活补贴">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.commonTag"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="是否享受护理补贴" prop="rate">
						    <el-select v-model="formData.isnursing" style="width: 100%;" placeholder="请选择是否享受护理补贴">
						    	<el-option :label="item" :value="item" v-for="(item, index) in Site.commonTag"></el-option>
						    </el-select>
						</el-form-item>
					</el-col>
				</el-row>
            	<el-form-item>
            		<el-button @click="dialogClose">取 消</el-button>
            		<el-button type="primary" @click="formSubmit">确 定</el-button>
            	</el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
    export default {
        data() {
			return {
				dialog: false,
				Home: [],
				Site: [],
				formData: {
					id: 0,
				}
			}
        },
		created() {
		},
		watch: {
			dialog () {
				if(!this.dialog) {
					this.clearFormData()
					this.$emit('getData')
				} else {
					this.getHome()
					this.getSite()
				}
			}
		},
        methods: {
			getHome () {
				this.$apiPost('home/getHomeList').then(res => {
					if(res.code == 1) {
						this.Home = res.data
					}
				})
			},
			getSite () {
				this.$apiPost('Index/getSiteFile').then(res => {
					if(res.code == 1) {
						this.Site = res.data
					}
				})
			},
			dialogClose(){
				this.$emit('dialogToggle')
			},
			clearFormData () {
				for(let i in this.formData){
					if(i == 'id') {
						this.formData[i] = 0
					} else {
						this.formData[i] = ''
					}
				}
			},
			// 保存编辑
			formSubmit() {
				if(!this.formData.homeid||this.formData.homeid==null){
					return this.$message.error('请选择户档！')
				}
				if(!this.formData.name||this.formData.name==null){
					return this.$message.error('请输入姓名！')
				}
				if(!this.formData.sn||this.formData.sn==null){
					return this.$message.error('请输入残疾证号码！')
				}
				if(this.formData.insurance1=='没参加'){
					this.formData.insurance2 = ''
				}
				if(this.formData.insurance3=='没参加'){
					this.formData.insurance4 = ''
				}
				this.$apiPost('Check/editData', this.formData).then(res => {
					if(res.code == 1) {
						this.$message.success(res.msg)
						this.dialogClose()
					} else {
						this.$message.error(res.msg)
					}
				})
			},
        }
    };
</script>
<style scoped>
	.mselect{
		width: 100%;
	}
	.mtdiv{
		margin-top: 10px;
		display: inline-block;
		width: 100%;
	}
	.mtdiv .mtdiv-v{
		float: left;
		width: 50%;
		margin-bottom: 5px;
		display: flex;
		align-items: center;
	}
	.mtdiv .mtdiv-v label{
		float: left;
		margin-right: 10px;
	}
	.mtdiv .el-input{
		float: left;
		width: 80%;
		margin: 5px 0;
	}
</style>
